/**
 */
package mvc_generator.mVCGenerator.impl;

import java.util.Collection;

import mvc_generator.mVCGenerator.Expression;
import mvc_generator.mVCGenerator.FieldAssignement;
import mvc_generator.mVCGenerator.For;
import mvc_generator.mVCGenerator.MVCGeneratorPackage;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>For</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ForImpl#getInitialisation <em>Initialisation</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ForImpl#getModification <em>Modification</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ForImpl#getBody <em>Body</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ForImpl extends ControlStructureImpl implements For
{
  /**
   * The cached value of the '{@link #getInitialisation() <em>Initialisation</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getInitialisation()
   * @generated
   * @ordered
   */
  protected FieldAssignement initialisation;

  /**
   * The cached value of the '{@link #getModification() <em>Modification</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getModification()
   * @generated
   * @ordered
   */
  protected FieldAssignement modification;

  /**
   * The cached value of the '{@link #getBody() <em>Body</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getBody()
   * @generated
   * @ordered
   */
  protected EList<Expression> body;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ForImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return MVCGeneratorPackage.Literals.FOR;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public FieldAssignement getInitialisation()
  {
    return initialisation;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetInitialisation(FieldAssignement newInitialisation, NotificationChain msgs)
  {
    FieldAssignement oldInitialisation = initialisation;
    initialisation = newInitialisation;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.FOR__INITIALISATION, oldInitialisation, newInitialisation);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setInitialisation(FieldAssignement newInitialisation)
  {
    if (newInitialisation != initialisation)
    {
      NotificationChain msgs = null;
      if (initialisation != null)
        msgs = ((InternalEObject)initialisation).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.FOR__INITIALISATION, null, msgs);
      if (newInitialisation != null)
        msgs = ((InternalEObject)newInitialisation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.FOR__INITIALISATION, null, msgs);
      msgs = basicSetInitialisation(newInitialisation, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.FOR__INITIALISATION, newInitialisation, newInitialisation));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public FieldAssignement getModification()
  {
    return modification;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetModification(FieldAssignement newModification, NotificationChain msgs)
  {
    FieldAssignement oldModification = modification;
    modification = newModification;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.FOR__MODIFICATION, oldModification, newModification);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setModification(FieldAssignement newModification)
  {
    if (newModification != modification)
    {
      NotificationChain msgs = null;
      if (modification != null)
        msgs = ((InternalEObject)modification).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.FOR__MODIFICATION, null, msgs);
      if (newModification != null)
        msgs = ((InternalEObject)newModification).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.FOR__MODIFICATION, null, msgs);
      msgs = basicSetModification(newModification, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.FOR__MODIFICATION, newModification, newModification));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Expression> getBody()
  {
    if (body == null)
    {
      body = new EObjectContainmentEList<Expression>(Expression.class, this, MVCGeneratorPackage.FOR__BODY);
    }
    return body;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.FOR__INITIALISATION:
        return basicSetInitialisation(null, msgs);
      case MVCGeneratorPackage.FOR__MODIFICATION:
        return basicSetModification(null, msgs);
      case MVCGeneratorPackage.FOR__BODY:
        return ((InternalEList<?>)getBody()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.FOR__INITIALISATION:
        return getInitialisation();
      case MVCGeneratorPackage.FOR__MODIFICATION:
        return getModification();
      case MVCGeneratorPackage.FOR__BODY:
        return getBody();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.FOR__INITIALISATION:
        setInitialisation((FieldAssignement)newValue);
        return;
      case MVCGeneratorPackage.FOR__MODIFICATION:
        setModification((FieldAssignement)newValue);
        return;
      case MVCGeneratorPackage.FOR__BODY:
        getBody().clear();
        getBody().addAll((Collection<? extends Expression>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.FOR__INITIALISATION:
        setInitialisation((FieldAssignement)null);
        return;
      case MVCGeneratorPackage.FOR__MODIFICATION:
        setModification((FieldAssignement)null);
        return;
      case MVCGeneratorPackage.FOR__BODY:
        getBody().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.FOR__INITIALISATION:
        return initialisation != null;
      case MVCGeneratorPackage.FOR__MODIFICATION:
        return modification != null;
      case MVCGeneratorPackage.FOR__BODY:
        return body != null && !body.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //ForImpl
